<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>对象</title>
</head>

<body>
  <script>
    // 声明对象
    let obj = {
      name: '小米10',
      age: 13,
      sex: '男',
      'goods-color': 'red',
      sayHi: function () {
        console.log('你好');
      }
    }
    console.log(obj);

    let obj1 = new Object()
    obj1.name = '李四'
    console.log(obj1);

    // 对象的查询2种方式
    // 对象名.属性名
    console.log(obj.name);
    // 对象名['属性名']
    console.log(obj['goods-color']);

    console.log('=====对象的方法=====');
    // console.log(obj.sayHi());     //undefined
    obj.sayHi()

    console.log('=====对象遍历forin方法=====');
    for (const key in obj) {
      console.log(key);    // 这个key是字符串类型,所以不推荐forin遍历数组
      console.log(obj[key]);
    }

  </script>
</body>

</html>